UNPKG

2.07 kBJavaScriptView Raw
1'use strict';
2
3var Path = require('path');
4var Should = require('should');
5var IFNode = require('../');
6var app = require('../examples/models/app');
7
8describe('Models', function() {
9 describe('Models loading', function() {
10 it('should initialize several schemas', function() {
11 var app = IFNode({
12 project_folder: Path.resolve(__dirname, '../examples/models_custom_schema'),
13 alias: 'models_custom_schema',
14 environment: 'custom-schema',
15 });
16
17 app.register([
18 'custom-schema',
19 'custom-schema-without-constructor',
20 'custom-schema-with-empty-driver'
21 ]);
22 app.load();
23 });
24
25 it('should throw doubling names error', function() {
26 (function() {
27 IFNode({
28 project_folder: Path.resolve(__dirname, '../examples/models_with_errors'),
29 alias: 'duplicated-names',
30 environment: 'duplicated-names'
31 }).load();
32 }).should.throw();
33 });
34
35 it('should throw alias doubling name error', function() {
36 (function() {
37 IFNode({
38 project_folder: Path.resolve(__dirname, '../examples/models_with_errors'),
39 alias: 'alias-duplicate-name',
40 environment: 'alias-duplicate-name'
41 }).load();
42 }).should.throw();
43 });
44 });
45
46 describe('app.Model(model_config: Object, [options: Object])', function() {
47 it('should exists', function() {
48 app.Model.should.be.an.Function;
49 });
50
51 it('should creates models', function() {
52 app.load();
53
54 var models = app.models;
55
56 Should.equal(models.FirstModel.sameMethod(), 1);
57
58 var SecondModel = models.SecondModel;
59
60 Should.equal(SecondModel.sameMethod(), 2);
61 Should.equal(SecondModel.custom_property, 'custom_value');
62 });
63 });
64});